import request from "@/utils/request";
import type { Category } from "@/types";

// 获取所有分类
export async function getCategories() {
  return (
    await request<Category[]>({
      url: "/categories",
      method: "get",
    })
  ).data;
}

// 根据ID获取单个分类
export async function getCategoryById(id: number) {
  return (
    await request<Category>({
      url: `/categories/${id}`,
      method: "get",
    })
  ).data;
}

// 创建新分类
export async function createCategory(data: Omit<Category, "id">) {
  return (
    await request({
      url: "/categories",
      method: "post",
      data,
    })
  ).data;
}
